package com.example.smartcs.controller;

import com.example.smartcs.model.HumanIntervention;
import com.example.smartcs.service.HumanInterventionService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 人工干预控制器
 */
@RestController
@RequestMapping("/api/interventions")
@RequiredArgsConstructor
public class HumanInterventionController {
    
    private final HumanInterventionService humanInterventionService;
    
    /**
     * 记录人工干预
     */
    @PostMapping
    public ResponseEntity<HumanIntervention> recordIntervention(@RequestBody HumanIntervention intervention) {
        return ResponseEntity.ok(humanInterventionService.recordIntervention(intervention));
    }
    
    /**
     * 获取会话的所有干预记录
     */
    @GetMapping("/session/{sessionId}")
    public ResponseEntity<List<HumanIntervention>> getSessionInterventions(@PathVariable String sessionId) {
        return ResponseEntity.ok(humanInterventionService.getSessionInterventions(sessionId));
    }
    
    /**
     * 获取消息的干预记录
     */
    @GetMapping("/message/{messageId}")
    public ResponseEntity<HumanIntervention> getMessageIntervention(@PathVariable String messageId) {
        return ResponseEntity.ok(humanInterventionService.getMessageIntervention(messageId));
    }
    
    /**
     * 更新干预记录
     */
    @PutMapping("/{id}")
    public ResponseEntity<HumanIntervention> updateIntervention(
            @PathVariable String id,
            @RequestBody HumanIntervention intervention) {
        intervention.setId(id);
        return ResponseEntity.ok(humanInterventionService.updateIntervention(intervention));
    }
    
    /**
     * 删除干预记录
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteIntervention(@PathVariable String id) {
        humanInterventionService.deleteIntervention(id);
        return ResponseEntity.ok().build();
    }
} 